package loot;

import util.Func;
import util.util.Hist;

public class ChestTable extends LootTable {

	private Hist<String>	pass1 = new Hist<String>();
	
	@Override
	public final Hist<String>	getLoot(int level) {
		//
		// Given the roll of R = 1d20 + level this is the result
		//
		Hist<String>	LL = new Hist<String>();
		
		addCopper(				pass1.get("addCopper").intValue() + level,				LL	);
		addSilverAndElectrum(	pass1.get("addSilverAndElectrum").intValue() + level,	LL	);
		addGold(				pass1.get("addGold").intValue() + level,				LL	);
		addPlatinum(			pass1.get("addPlatinum").intValue() + level,			LL	);
		addGems(				pass1.get("addGems").intValue() + level,				LL	);
		addArt(					pass1.get("addArt").intValue() + level,					LL	);
		addMagicItems(			pass1.get("addMagicItems").intValue() + level,			LL	);
		
		return LL;
	}

	@Override
	public void makeRolls() {
		pass1.put("addCopper", Func.roll(20));
		pass1.put("addSilverAndElectrum", Func.roll(20));
		pass1.put("addGold", Func.roll(20));
		pass1.put("addPlatinum", Func.roll(20));
		pass1.put("addGems", Func.roll(20));
		pass1.put("addArt", Func.roll(20));
		pass1.put("addMagicItems", Func.roll(20));
	}

	public void addCopper(int R, Hist<String> LL) {
		if (R >= 10)				{	LL.add("copper pieces", Func.roll(4,8)*100);		}
	}
	public void addSilverAndElectrum(int R, Hist<String> LL) {
		if (R >= 10 && R <= 18)		{	LL.add("silver pieces", Func.roll(3,8)*10);			}
		if (R >= 19)				{	LL.add("electrum pieces", Func.roll(3,8)*10);		}
	}
	public void addGold(int R, Hist<String> LL) {
		if (R >= 15)				{	LL.add("gold pieces", Func.roll(3,8)*10);			}
	}
	public void addPlatinum(int R, Hist<String> LL) {
		if (R >= 19)				{	LL.add("platinum pieces", Func.roll(3,8));			}
	}
	public void addGems(int R, Hist<String> LL) {
		if (R >= 17 && R <= 22)		{	LL.add("ornamental gems", Func.roll(2,8));			}
		if (R >= 23 && R <= 27)		{	LL.add("semiprecious gems", Func.roll(2,8));		}
		if (R >= 28)				{	LL.add("precious gems", Func.roll(1,8));			}
	}
	public void addArt(int R, Hist<String> LL) {
		if (R >= 23 && R <= 29)		{	LL.add("decorative art objects", Func.roll(1,8));	}
		if (R >= 30)				{	LL.add("fine art objects", Func.roll(1,8));			}
	}
	public void addMagicItems(int R, Hist<String> LL) {
		if (R >= 17 && R <= 22)		{	LL.add("common potion", Func.roll(2,4));			}
		if (R >= 23 && R <= 26)		{	LL.add("uncommon magic item", Func.roll(4)-1);		}
		if (R >= 27 && R <= 29)		{	LL.add("rare magic item", Func.roll(2));			}
		if (R >= 30 && R <= 32)		{	LL.add("very rare magic item", 1);					}
		if (R >= 31)				{	LL.add("legendary magic item", 1);					}
	}

}
